//
//  Today_Today_Debris_Tag_CollectionViewCell.m
//  Time
//
//  Created by dllo on 16/7/28.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "Today_Today_Debris_Tag_CollectionViewCell.h"

@interface Today_Today_Debris_Tag_CollectionViewCell ()
/**
 *  标签名
 */
@property (nonatomic,retain) UILabel *tagLabel;
/**
 *  条目数label
 */
@property (nonatomic,retain) UILabel *countLabel;
/**
 *  背景图
 */
@property (nonatomic,retain) UIImageView *backImageView;
/**
 *  毛玻璃层
 */
@property (nonatomic,retain) UIVisualEffectView *view;
@end

@implementation Today_Today_Debris_Tag_CollectionViewCell

-(void)dealloc{
    [_model release];
    [_tagLabel release];
    [_countLabel release];
    [_backImageView release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.backImageView];
        [_backImageView release];
        
        self.tagLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.tagLabel];
        [_tagLabel release];
        
        self.countLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.countLabel];
        [_countLabel release];
        
        UIBlurEffect *blu = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
        self.view = [[UIVisualEffectView alloc] initWithEffect:blu];
        [self.backImageView addSubview:self.view];
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.backImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.backImageView.clipsToBounds = YES;
    [self.backImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(0);
        make.right.equalTo(self.contentView.mas_right).offset(0);
        make.top.equalTo(self.contentView.mas_top).offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
    }];
    
    [self.view mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.backImageView.mas_left).offset(0);
        make.right.equalTo(self.backImageView.mas_right).offset(0);
        make.top.equalTo(self.backImageView.mas_top).offset(0);
        make.bottom.equalTo(self.backImageView.mas_bottom).offset(0);
    }];
    self.view.alpha = 0.3;
    
    self.tagLabel.numberOfLines = 0;
    self.tagLabel.textAlignment = NSTextAlignmentCenter;
    self.tagLabel.textColor = [UIColor whiteColor];
    [self.tagLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
        make.centerY.equalTo(self.contentView.mas_centerY).offset(0);
        make.width.mas_equalTo(SWIDTH / 3.0 - 10);
        make.height.mas_equalTo([Tools getTextHeight:self.model.tag withWidth:SWIDTH / 3.0 - 10 withFontSize:17.0]);
    }];
    
    self.countLabel.textColor = [UIColor lightGrayColor];
    self.countLabel.textAlignment = NSTextAlignmentCenter;
    self.countLabel.font = [UIFont systemFontOfSize:10.0];
    [self.countLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX).offset(0);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
        make.width.mas_equalTo(SWIDTH / 3.0 - 10);
        make.height.mas_equalTo(20);
    }];
    
}

-(void)setModel:(SCBTagModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.backImageView setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
    self.tagLabel.text = model.tag;
    self.countLabel.text = [NSString stringWithFormat:@"%@条",model.count];
}

@end
